
#import "PUFoodDetailsView.h"

@implementation PUFoodDetailsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    self.pictureView = [[UIImageView alloc]init];
    self.pictureView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.pictureView];
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset = 0;
        make.height.offset = _window_width;
    }];
    
    UIView *userView = [[UIView alloc]init];
    userView.backgroundColor = UIColor.whiteColor;
    userView.layer.cornerRadius = 10;
    userView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
    userView.layer.masksToBounds = true;
    [self addSubview:userView];
    [userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset = 0;
        make.height.offset = 50;
    }];
    
    self.headImage = [[UIImageView alloc]init];
    self.headImage.contentMode = UIViewContentModeScaleAspectFill;
    self.headImage.clipsToBounds = true;
    self.headImage.layer.cornerRadius = 32/2;
    [userView addSubview:self.headImage];
    [self.headImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset = 15;
        make.top.offset = 12;
        make.width.height.offset = 32;
    }];
    
    self.nameLab = [[UILabel alloc]init];
    self.nameLab.text = @"发布人";
    self.nameLab.font = [UIFont boldSystemFontOfSize:14];
    [userView addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImage.mas_right).offset = 8;
        make.centerY.equalTo(self.headImage);
    }];
}

- (void)setModel:(PUFoodModel *)model {
    self.nameLab.text = model.username;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:[NSString urlSignImage:model.userimage]]];
    [self.pictureView sd_setImageWithURL:[NSURL URLWithString:model.cover]];
}

@end
